package com.yekong.house.web.utils;

import com.yekong.house.common.model.User;
import com.yekong.house.common.vo.ResultMsg;
import org.springframework.util.StringUtils;

import java.util.Objects;

public class UserHelper {

    public static ResultMsg validate(User account){
        /**
         * 用户注册校验
         */
        if(StringUtils.isEmpty(account.getEmail())) {
            return ResultMsg.errorMsg("Email 有误");
        }
        if(StringUtils.isEmpty(account.getPasswd())||StringUtils.isEmpty(account.getConfirmPasswd())){
            return ResultMsg.errorMsg("密码不一致");
        }
        if(account.getPasswd().length() < 6) {
            return ResultMsg.errorMsg("密码小于6位");
        }
        return ResultMsg.successMsg("");
    }


    /**
     * 重置密码验证
     *
     * @param key
     * @param password
     * @param comfirmPassword
     * @return
     */
    public static ResultMsg validateResetPassword(String key,String password,String comfirmPassword){
        if(StringUtils.isEmpty(key)||StringUtils.isEmpty(password)||StringUtils.isEmpty(comfirmPassword)){
            return ResultMsg.errorMsg("参数有误");
        }
        if(!Objects.equals(password,comfirmPassword)) {
            return ResultMsg.errorMsg("密码必须;与确认密码一致");
        }
        return ResultMsg.successMsg("");
    }


}
